package com.wolfpire.workflow.dao.impl;

import java.util.List;
import java.util.Map;

import org.hibernate.Query;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

import com.wolfpire.system.common.base.dao.impl.BaseHibernateDao;
import com.wolfpire.workflow.dao.TrunDao;
import com.wolfpire.workflow.om.Trun;

@Repository("trunDao")
public class TrunDaoImpl extends BaseHibernateDao<Trun, Long> implements TrunDao {

	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> getTrunList(Long taskId){
		
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT T.TASK_ID,T.USER_ID,T.USER_NAME,T.TRUN_USER_ID,T.TRUN_USER_NAME,T.REMARKS,TO_CHAR(T.CREAT_TIME, 'YYYY-MM-DD HH24:MI') CREAT_TIME ");
		sql.append(" FROM  WF_TRUN T WHERE 1=1 ");
		if(taskId!=null){
			sql.append(" AND T.TASK_ID = ").append(taskId);
		}
		
		Query query = getSession().createSQLQuery(sql.toString());
		return query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
	}
}
